package com.pine.common.beans.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

/**
 * <p>
 * 分页请求
 * </p>
 *
 * @author pine manage
 * @since 2024-08-09
 */
@Schema(title = "PageRequest", description = "分页请求")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageRequest<T> implements Serializable {
    @Serial
    private static final long serialVersionUID = -5265398507538196628L;

    /**
     * 页码
     */
    @JsonProperty("pageNum")
    @Schema(title = "pageNum", description = "页码")
    private Integer pageNum;

    /**
     * 每页大小
     */
    @JsonProperty("pageSize")
    @Schema(title = "pageSize", description = "每页大小")
    private Integer pageSize;

    /**
     * 数据
     */
    @JsonProperty("data")
    @Schema(title = "data", description = "数据")
    private T data;

    public PageRequest(T data) {
        this.data = data;
    }

    /**
     * 默认分页参数
     */
    public void defaultPage() {
        if (Objects.isNull(this.pageNum)) {
            this.pageNum = 1;
        }
        if (Objects.isNull(this.pageSize)) {
            this.pageSize = 20;
        }
    }

    /**
     * 大数据量导出时的分页参数
     */
    public void exportPage() {
        if (Objects.isNull(this.pageNum)) {
            this.pageNum = 1;
        }
        if (Objects.isNull(this.pageSize)) {
            this.pageSize = 1000;
        }
    }
}
